/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.base.exception;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

class ConverterUtil {
	public static <From, To> Collection<To> convert(Collection<From> from, Converter<From, To> converter) {
		List<To> to = new ArrayList<To>(from.size());

		for (From element : from) {
			to.add(converter.convert(element));
		}

		return to;
	}
	
	public static <T> String join(Collection<T> collection, String separator) {
		StringBuilder joined = new StringBuilder();

		for (Iterator<T> iterator = collection.iterator() ; iterator.hasNext() ;) {
			joined.append(iterator.next().toString());

			if (iterator.hasNext()) {
				joined.append(separator);
			}
		}

		return joined.toString();
	}
}